class PasswordException(Exception):
    def __init__(self,passwd,min_length):
        self.passwd=passwd
        self.min_length=min_length
        
    def __str__(self):
        return "%s的密码错误，密码的最小长度为:%s" %(self.passwd,self.min_length)
        
def reg(username,passwd):
    if len(passwd) < 6:
        raise PasswordException(passwd,6) #抛出自定义的异常
    else:
        print("用户名为：%s，密码为:%s" %(username,passwd))

try:
    reg("lucy","23456")
except PasswordException as ex:
    print(ex)
except Exception as ex:
    print(ex)
else:
    print("无异常时执行！")
finally:
    print("不管有没有异常都会执行！")
    